﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class 实验三_3_3_3_3 : System.Web.UI.Page
{
    StudentClassesDataContext db = new StudentClassesDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        var stus = from x in db.Student
                   where x.name.Contains(TextBox1.Text) && x.sex.Equals(DropDownList1.SelectedValue)
                   select x;
        GridView1.DataSource= stus;
        GridView1.DataBind();
                  
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        Student student = new Student();
        student.name=TextBox2.Text;
        student.id=TextBox4.Text;
        student.sex = TextBox3.Text.Equals("男") ? '1' : '0';
        try
        {
            db.Student.InsertOnSubmit(student);
            db.SubmitChanges();
            Button1_Click(sender, e);
        }
        catch(Exception) {
        Response.Write("Error");
        }

    }

    protected void Button3_Click(object sender, EventArgs e)
    {
        var y = db.Student.Where(x => x.id.Equals(TextBox5.Text));
        db.ExecuteCommand("delete from Student where id=" + TextBox5.Text);
        Button1_Click(sender, e);
    }
}